package com.jservice.web.editor;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baidu.ueditor.ActionEnter;
import com.jservice.framework.dto.Setting;
import com.jservice.web.base.JBaseController;

/**
 * NeditorController - 富文本编辑器控制类
 *
 * @Author cwledit
 * @DATE 2017/7/6.
 */
public class NeditorController extends JBaseController{

    public void index(){
        String rs = ActionEnter.me().exec(getRequest());
        System.out.println(rs);
        String actionType = getRequest().getParameter("action");
        if("config".equals(actionType)){
            JSONObject jsonObject = JSON.parseObject(rs);
            jsonObject.put("imageUrlPrefix","");
            jsonObject.put("scrawlUrlPrefix", "");
            jsonObject.put("snapscreenUrlPrefix", "");
            jsonObject.put("catcherUrlPrefix", "");
            jsonObject.put("videoUrlPrefix", "");
            jsonObject.put("fileUrlPrefix", "");
            jsonObject.put("imageManagerUrlPrefix", "");
            jsonObject.put("fileManagerUrlPrefix", "");
            rs = JSON.toJSONString(jsonObject);
        }

        if ("uploadimage".equals(actionType)){
            JSONObject jsonObject = JSON.parseObject(rs);
            if ("SUCCESS".equals(jsonObject.getString("state"))){
                String imgUrl = jsonObject.getString("url");
                jsonObject.put("url", Setting.getConfig("imagehost")+imgUrl);
                rs = jsonObject.toJSONString();
            }
        }

        renderHtml(rs);

    }

}
